using System;
using System.Linq;

namespace SonarCaptain
{
    enum MapState
    {
        EMPTY, ISLAND, TRACK, PLAYER, MASK
    }
    class Map
    {
        public int RowCount {get; set;} = Game.ROW_COUNT;
        public int ColumnCount {get; set;} = Game.COLUMN_COUNT;
        public MapState[,] MapInfo {get;} = new MapState[Game.ROW_COUNT, Game.COLUMN_COUNT];
        public Map()
        {
            var random = new Random();
            for (int i=0; i < Game.ISLAND_COUNT; i++)
            {
                while (true)
                {
                    int rowIndex = random.Next(1, RowCount-1);
                    int columnIndex = random.Next(1, ColumnCount-1);
                    if (MapInfo[rowIndex, columnIndex] == MapState.EMPTY)
                    {
                        MapInfo[rowIndex, columnIndex] = MapState.ISLAND;
                        break;
                    }
                }
            }
        }
        public void PrintMap()
        {
            Console.Write(' ');
            for (int i=0; i < ColumnCount; i++)
            {
                Console.Write(' ');
                Console.Write(i.ToString().Last());
            }
            Console.WriteLine();
            for (int r=0; r < RowCount; r++)
            {
                Console.Write((char) (r+'A'));
                for (int c=0; c < ColumnCount; c++)
                {
                    Console.Write(' ');
                    switch (MapInfo[r, c])
                    {
                    case MapState.EMPTY:
                        Console.Write('+');
                        break;
                    case MapState.ISLAND:
                        Console.Write('O');
                        break;
                    case MapState.PLAYER:
                        Console.Write('x');
                        break;
                    case MapState.TRACK:
                        Console.Write('*');
                        break;
                    case MapState.MASK:
                        Console.Write('.');
                        break;
                    }
                }
                Console.WriteLine();
            }
            Console.WriteLine("图例：空（+）岛屿（O）玩家（x）轨迹（*）蒙版（.）");
        }
    }
}